Graphics using the traditional R way

To plot a Spectra object using the base R graphics, use spc.plot(). This method uses the R function matplot(). If there are too many observations (rows), plotting with matplot() can be very slow and may result in a figure cluttered with too many curves. To avoid such a disturbance such a case, use the argument maxSp. The following command will graph four spectra only, distributed evenly between the first and the last rows :

par(mfrow=c(1,2))
spc.plot(myS)
spc.plot(myS,maxSp=4) 

par(mfrow=c(1,1))

Depth Plots

If the dataset contains an ancillary data column named DEPTH, then plotting the Spectra object with respect to depth can be achieved by spc.plot.depth where the depth dimension is drawn on a reversed y axis:

par(mfrow=c(1,3))
spc.plot.depth(myS, "anap_300") 
spc.plot.depth(myS, c("anap_300","anap_500")) 
spc.plot.depth(myS, c("anap_300", "Snap"))

par(mfrow=c(1,1))

Time Plots

Time plots consist of plotting a Spectra object with respect to observation number (channels with respect to row index) :

spc.plot.time(myS)

The previous command draws a maximum number of 50 channels (default maxSp=50) among all spectral data. It is also possible to draw only 7 spectra (covering the whole spectral range).

spc.plot.time(myS, maxSp=7) 

Grid Plots

A SpcList object containing several Spectra objects can be graphed in the same page in a grid structure. The function spc.plot.grid() calls spc.plot() for every grid element. The grid panels are named according to the Station header value.

spc.plot.grid(BL,"spc.plot", nnrow=2, nncol=2)

It is also possible to draw a grid of depth profiles if the dataset contains a column called DEPTH. The following command will plot depth profiles of 10 columns evenly distributed between the first and last columns. If the function matches columns that have different units, a new x-axis will be drawn at the top for the additional unit. Only two units will are supported at this moment.

spc.plot.grid(BL,"spc.plot.depth", nnrow=2, nncol=2)

Additional arguments that can be used to format regular plotting functions of R can also be passed :

spc.plot.grid(BL,"spc.plot.depth", nnrow=2, nncol=2,ylim=c(60,0)) 

The function spc.plot.grid() will draw only a number of maxSp columns by default. It is possible to change this behavior by setting the input argument maxSp.

spc.plot.grid(BL,"spc.plot.depth", nnrow=2, nncol=2, maxSp=5)

To plot only one column per panel, make sure the name (or the column index) of the variable is passed to spc.plot.depth() through spc.plot.grid().

spc.plot.grid(BL,"spc.plot.depth", X="anap_300",nnrow=2, nncol=2)

Plots Overlays

It is also possible to draw spectra from various SpcLists objects on the same graph. Overlay of Spectra plots can be achieved using spc.plot.overlay.

spc.plot.overlay(BL,lw=2)

As of now, only overlaying lines with spc.plot or spc.lines have been implemented.

Interactive Graphics with Javascript libraries

To plot a Spectra object with plotly, simply pass the Spectra object to spc.plot.plotly()

h <- spc.plot.plotly(myS)
class(h)
## [1] "plotly"     "htmlwidget"
h
## Warning in arrange_impl(.data, dots): '.Random.seed' is not an integer
## vector but of type 'NULL', so ignored

The variable myS contains data from several casts (depth profiles). To isolate a cast, we use spc.makeSpcList().

BL <- spc.makeSpcList(myS, "CAST")

To plot the depth profile we pass the SpcList object we just created to spc.plot.depth.plotly()

spc.plot.depth.plotly(BL[[4]])

To make a map using rbokeh tools, first manually load the maps package providing the basemap showing the continents and pass the Spectra object to spc.plot.map.rbokeh(). The 26 observations stored in this object come from a total of 4 stations which are shown in the map below :

library("maps")
spc.plot.map.rbokeh(myS)

To plot a Spectra object with respect to time, simply pass the object to spc.plot.time.plotly()

spc.plot.time.plotly(myS)